﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wq.Extensions;
using Wq.Extensions.Common;
using Wq.Extensions.Repository;
using Wq.ManagerService.Models;
using Wq.Model;
using XAct;

namespace Wq.Application
{
    /// <summary>
    /// 系统配置 
    /// </summary>
    public class SettingsApplication : BaseApplication
    {

        private readonly RedisBaseRepository redisRepository;

        /// <summary>
        /// 系统配置
        /// </summary>
        /// <param name="redisRepository"></param>
        public SettingsApplication(RedisBaseRepository redisRepository) => this.redisRepository = redisRepository;

        public SiteSetting GetSetting()
        {
          return  redisRepository.Get(SysCacheKey.SiteSetting, () => {
              SiteSetting setting = new SiteSetting();
              setting.FileDomain = AppSettings.app("AliyunOss:FileDomain");
              setting.TencentMapKey = "KODBZ-ZGAW2-DINUR-C4AZJ-6J7LO-3WB2X";
              return setting;
            }).Result;
        }

        /// <summary>
        /// 保存配置
        /// </summary>
        /// <returns></returns>
        public void SetSetting(SiteSetting setting)
        {
             redisRepository.Remove(SysCacheKey.SiteSetting);
             redisRepository.Get(SysCacheKey.SiteSetting, () => { return setting; });
        }
    } 
}
